package com.ruoyi.project.wx.carCard.controller;


import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.wx.carCard.domain.CarCard;
import com.ruoyi.project.wx.carCard.service.CarCardService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车牌信息
 */
@Controller
@RequestMapping("/wx/carCard")
public class CarCardController extends BaseController {

    private String prefix = "wx/carCard";

    @Autowired
    private CarCardService carCardService;

    @RequiresPermissions("wx:carCard:view")
    @GetMapping()
    public String toCarCardList()
    {
        return prefix + "/list";
    }

    @RequiresPermissions("wx:carCard:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CarCard carCard) {
        startPage();
        List<CarCard> carCardCarList = carCardService.carCardlist(carCard);
        return getDataTable(carCardCarList);
    }

    /**
     * 修改
     */
    @RequiresPermissions("wx:carCard:update")
    @PostMapping("/update")
    @ResponseBody
    public AjaxResult update(CarCard carCard)
    {
        return toAjax(carCardService.updateCarCardInfo(carCard));
    }

    @RequiresPermissions("wx:carCard:remove")
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        try
        {
            return toAjax(carCardService.delCarCardByIds(ids));
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
    }

    /**
     * 修改用户
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        mmap.put("carCard", carCardService.selectCarCardById(id));
        return prefix + "/edit";
    }

    /**
     * 跳转新增车牌
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增车牌
     */
    @RequiresPermissions("system:carCard:add")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CarCard carCard)
    {
        return toAjax(carCardService.insert(carCard));
    }
}
